import api from '../../http/apis/apis'
export default {
    namespaced: true,
    //下面写请求
    state: {
        currentPage: 1,
        pageSize: 3,
        //保存销售员的所有的订单
        OrderData: {
            total: 0,
            totalPages: 0,
            data: [],

        },
        update: {},//修改
    },
    mutations: {
        changeOrder(state, val) {
            state.OrderData = val
        },
        //改变当前页
        setCurrent(state, newcurrent) {
            state.currentPage = newcurrent
        },
        //每页显示数量
        setPageSize(state, newpagesize) {
            state.pageSize = newpagesize
        },
        //修改订单的第一步
        changeUpdate(state, newval) {
            state.update = newval
        }
    },
    actions: {
        //销售员订单的列表
        async getSalesOrder(context, id) {
            id = '5f6718565a7b2c556858174d'
            const { data } = await api.order.getSalesOrder({
                _id: id,
                currentPage: context.state.currentPage,
                pageSize: context.state.pageSize,
            })
            if (data.status > 0) {
                context.commit('changeOrder', data.data)
            }
        },
        //删除订单
        async deletOrder(context, _id) {
            const { data } = await api.order.deletOrder({ _id })
            if (data.status > 0) {
                context.dispatch('getSalesOrder')
            }
        },
        //获取一个订单信息
        async getOrder(context, _id) {
            const { data } = await api.order.getOrder({ _id });
            if (data.status > 0) {
                context.commit('changeUpdate', data.data)
            }
        },
        //修改订单
        async updateOrderSuccess(context, val) {
            const { data } = await api.order.updateOrderSuccess(val);
            if (data.status) {
                context.dispatch('getSalesOrder')
            }
        }
    }

}